<?php
/**
 * view: task/log_detail
 * @var CSService\Controller\Task
 * @var \Ke\Web\Context $this
 * @var \Ke\Web\Web     $web
 * @var string          $content
 */


$log = $this->log ?? new \CSService\Model\Task\Task_Log();

?>
<a href="<?php print $web->uri($web->http->query('ref', 'task/log')) ?>" class="ui primary button">返回</a>
<div class="ui horizontal divider">任务日志</div>
<table class="ui table celled">
	<thead>
	<tr>
		<th colspan="2"><code><?php print $log->command_name; ?></code></th>
	</tr>
	</thead>
	<tbody>
	<tr>
		<td class="collapsing"><strong>项目</strong></td>
		<td><?php print $log->project_name; ?></td>
	</tr>
	<tr>
		<td class="collapsing"><strong>服务器</strong></td>
		<td><?php print $log->lan_ip; ?></td>
	</tr>
	<tr>
		<td class="collapsing"><strong>执行用户</strong></td>
		<td><?php print $log->user_name; ?></td>
	</tr>
	<tr>
		<td class="collapsing"><strong>执行时间</strong></td>
		<td><?php print date('Y-m-d H:i:s', $log->created_at); ?></td>
	</tr>
	</tbody>
</table>
<?php
$misc = $log->misc;
$split = explode('{-------------------------------------------------------}', $misc);
$names = [
	'command',
	'error',
	'stderr',
	'stdout',
];
foreach ($split as $index => $segment) {
	$name = $names[$index] ?? '';
	if (!empty($segment) || $index == 0 || $index === 3) {
		print '<div class="ui horizontal divider">' . $name . '</div>';
		print '<pre>' . $segment . '</pre>';
	}
}
?>
